<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top:50px"
    cancelText="关闭">
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="编号">
              <a-input placeholder="请输入编号" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="名称">
              <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="联系人">
                <a-input placeholder="请输入联系人" v-model="queryParam.contact"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="erp_status"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
<!--    <div class="table-operator">-->
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
<!--      <a-button type="primary" icon="download" @click="handleExportXls('供应商')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"-->
<!--                @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
<!--      &lt;!&ndash; 高级查询区域 &ndash;&gt;-->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal"-->
<!--                     @handleSuperQuery="handleSuperQuery"></j-super-query>-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel">-->
<!--            <a-icon type="delete"/>-->
<!--            删除-->
<!--          </a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作-->
<!--          <a-icon type="down"/>-->
<!--        </a-button>-->
<!--      </a-dropdown>-->
<!--    </div>-->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

      </a-table>
    </div>
  </a-card>
  </j-modal>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'

export default {
  name: 'ErpSupplierList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {

  },
  props:{
    modalWidth: {
      type: Number,
      required: false,
      default: 1250
    },
    checkval: {
      type: String,
      default: 'radio'
    }
  },
  data() {
    return {
      description: '供应商管理页面',
      title: '选择供应商',
      visible: false,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '编号',
          align: "center",
          dataIndex: 'code'
        },
        {
          title: '名称',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '类型',
          align: "center",
          dataIndex: 'type_dictText'
        },
        {
          title: '联系人',
          align: "center",
          dataIndex: 'contact'
        },
        {
          title: '联系电话',
          align: "center",
          dataIndex: 'telephone'
        },
        {
          title: '电子邮箱',
          align: "center",
          dataIndex: 'email'
        },
        {
          title: '邮编',
          align: "center",
          dataIndex: 'zipCode'
        },
        {
          title: '传真',
          align: "center",
          dataIndex: 'fax'
        },
        {
          title: '地址',
          align: "center",
          dataIndex: 'address'
        },
        {
          title: '开户银行',
          align: "center",
          dataIndex: 'bankName'
        },
        {
          title: '银行账号',
          align: "center",
          dataIndex: 'accountNo'
        },
        {
          title: '委托代理人',
          align: "center",
          dataIndex: 'agent'
        },
        {
          title: '电子承兑开户行',
          align: "center",
          dataIndex: 'ebaBankName'
        },
        {
          title: '电子承兑账号',
          align: "center",
          dataIndex: 'ebaAccountNo'
        },
        {
          title: '备注',
          align: "center",
          dataIndex: 'remark'
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'status_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/base/erpSupplier/list",
        delete: "/base/erpSupplier/delete",
        deleteBatch: "/base/erpSupplier/deleteBatch",
        exportXlsUrl: "/base/erpSupplier/exportXls",
        importExcelUrl: "base/erpSupplier/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleSubmit() {
      this.getGoodsSelectRows();
      this.searchReset(false)
      this.onClearSelected();
      this.close();
    },
    add() {
      this.showModal();
    },
    showModal() {
      this.visible = true;
      this.loadData();
    },
    getGoodsSelectRows() {
      let selectedRow = null;
      if(this.checkval=='radio'){
        selectedRow = this.selectionRows[0];
      }else{
        selectedRow = this.selectedRowKeys
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      this.$emit("handlerOk", selectedRow);
    },
    close() {
      this.searchReset(false);
      this.visible = false;
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'code', text: '编号', dictCode: ''})
      fieldList.push({type: 'string', value: 'name', text: '名称', dictCode: ''})
      fieldList.push({type: 'string', value: 'contact', text: '联系人', dictCode: ''})
      fieldList.push({type: 'string', value: 'telephone', text: '联系电话', dictCode: ''})
      fieldList.push({type: 'string', value: 'email', text: '电子邮箱', dictCode: ''})
      fieldList.push({type: 'string', value: 'zipCode', text: '邮编', dictCode: ''})
      fieldList.push({type: 'string', value: 'fax', text: '传真', dictCode: ''})
      fieldList.push({type: 'string', value: 'address', text: '地址', dictCode: ''})
      fieldList.push({type: 'string', value: 'bankName', text: '开户银行', dictCode: ''})
      fieldList.push({type: 'string', value: 'accountNo', text: '银行账号', dictCode: ''})
      fieldList.push({type: 'int', value: 'status', text: '状态', dictCode: 'erp_status'})
      fieldList.push({type: 'string', value: 'remark', text: '备注', dictCode: ''})
      fieldList.push({type: 'string', value: 'agent', text: '委托代理人', dictCode: ''})
      fieldList.push({type: 'string', value: 'ebaBankName', text: '电子承兑开户行', dictCode: ''})
      fieldList.push({type: 'string', value: 'ebaAccountNo', text: '电子承兑账号', dictCode: ''})
      fieldList.push({type: 'string', value: 'type', text: '类型', dictCode: "erp_supplier_type,name,id"})
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>